<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Contact
 *
 * @author khavu
 */
class Default_Model_Procedures extends Zend_Db_Table {

    protected $_name = 'procedures';
    protected $_primary = 'proid';
    protected $db;

    public function __construct() {
        $this->db = Zend_Registry::get('connectDb');
    }

    public function getAll($arrParam = null, $opption = null) {
        $db = Zend_Registry::get('connectDb');
        $lang = (isset($arrParam['lang'])) ? $arrParam['lang'] : "en";
        if ($lang == 'en') {
            $select = $db->select()
                         ->from('procedures AS p', array('proid', 'status', 'title AS title', 'en_content AS content', 'datecreated AS date', 'uidcreated AS user'))
                         ->where('status = ?', '1')
                         ->order('order ASC');
        } else {
            $select = $db->select()
                         ->from('procedures AS p', array('proid', 'status', 'title_vi AS title', 'vi_content AS content', 'datecreated AS date', 'uidcreated AS user'))
                         ->where('status = ?', '1')
                         ->order('order ASC');
        }
        $result = $db->fetchAll($select);
        return $result;
    }

    public function getItem($arrParam = null, $opption = null) {
        
        $db = Zend_Registry::get('connectDb');
        $lang = (isset($arrParam['lang'])) ? $arrParam['lang'] : "en";
        $id = (isset($arrParam['id'])) ? $arrParam['id'] : NULL;
        if (isset($arrParam['id'])) {
            $id = trim($arrParam['id']);
            if ($lang == 'en') {
                $select = $db->select()
                         ->from('procedures AS p', array('proid', 'status', 'title AS title', 'en_content AS content', 'datecreated AS date', 'uidcreated AS user'))
                         ->where("status = '1' AND proid = '$id' ");
            } else {
                $select = $db->select()
                         ->from('procedures AS p', array('proid', 'status', 'title_vi AS title', 'vi_content AS content', 'datecreated AS date', 'uidcreated AS user'))
                         ->where("status = '1' AND proid = '$id' ");
            }
            
            return $db->fetchAll($select);
        }
        
    }

}